<template>
  <template v-for="subItem in menuList" :key="subItem.path">
    <template v-if="subItem.children?.length">
      <el-sub-menu :index="subItem.path">
        <template #title>
          <el-icon>
            <component :is="subItem.meta.icon" />
          </el-icon>
          <!-- <Icon :icon="subItem.meta.icon" /> -->
          <span class="sle">{{ subItem.meta.title }}</span>
        </template>
        <SubMenu :menu-list="subItem.children" />
      </el-sub-menu>
    </template>
    <template v-else>
      <el-menu-item v-if="!subItem.meta.isHidden" :index="subItem.path" @click="handleClickMenu(subItem)">
        <!-- <Icon :icon="subItem.meta.icon" /> -->
        <el-icon>
          <component :is="subItem.meta.icon" />
        </el-icon>
        <template #title>
          <span class="sle">{{ subItem.meta.title }}</span>
        </template>
      </el-menu-item>
    </template>
  </template>
</template>

<script setup lang="ts">
import type { RouteRecordRaw } from "vue-router";
import { useRouter } from "vue-router";

defineProps<{ menuList: any }>();
defineOptions({
  name: "SubMenu"
});

/**
 * @description 路由钩子
 */
const router = useRouter();

/**
 * @description 菜单点击跳转
 * @param subItem 点击跳转项
 */
const handleClickMenu = (subItem: RouteRecordRaw) => {
  router.push(subItem.path);
};
</script>

<style lang="scss">
.el-sub-menu .el-sub-menu__title:hover {
  color: var(--el-menu-hover-text-color) !important;
  background-color: transparent !important;
}

.el-menu--collapse {
  .is-active {
    .el-sub-menu__title {
      color: #ffffff !important;
      background-color: var(--el-color-primary) !important;
    }
  }
}

.el-menu-item {
  &:hover {
    color: var(--el-menu-hover-text-color);
  }

  &.is-active {
    color: var(--el-menu-active-color) !important;

    // background-color: var(--el-menu-active-bg-color) !important;
    // background-color: white !important;
    &::before {
      position: absolute;
      top: 0;
      bottom: 0;
      width: 4px;
      left: 0px;
      content: "";
      // background-color: var(--el-color-primary);
      // background-color: white;
    }
  }
}

.vertical,
.classic,
.transverse {
  .el-menu-item {
    &.is-active {
      &::before {
        left: 0;
      }
    }
  }
}

.columns {
  .el-menu-item {
    &.is-active {
      &::before {
        right: 0;
      }
    }
  }
}

.classic,
.transverse {
  #driver-highlighted-element-stage {
    background-color: #606266 !important;
  }
}
</style>
